VERSION 5.00
Begin VB.Form Window 
   Appearance      =   0  'Flat
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "X-Bot: Configuring DNS"
   ClientHeight    =   720
   ClientLeft      =   45
   ClientTop       =   315
   ClientWidth     =   5490
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   720
   ScaleWidth      =   5490
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.Image Image1 
      Height          =   480
      Left            =   120
      Picture         =   "dnsconfig.frx":0000
      Top             =   120
      Width           =   480
   End
   Begin VB.Label KMWarn 
      Alignment       =   2  'Center
      BackColor       =   &H00C0FFFF&
      Caption         =   "Please do not use your keyboard or mouse at this time"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   720
      Width           =   4815
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Configuring X-Bot DNS Settings..."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   360
      Left            =   840
      TabIndex        =   0
      Top             =   120
      Width           =   4185
   End
End
Attribute VB_Name = "Window"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim AppDir As String


Private Sub Form_Load()
Me.Visible = True
DoEvents

AppDir = Command ' (app to be called DnsConfig.exe %AppDir%)
On Error Resume Next

' standardize Appdir
If Right(AppDir, 1) <> "\" And Right(AppDir, 1) <> "/" Then
    AppDir = AppDir & "\"
End If
'MsgBox AppDir

' Build a tempoary batch file to do what we want
Open AppDir & "ipconfig_t.bat" For Output As #1
    Print #1, "ipconfig /all > " & AppDir & "ipconfig_out.txt"
    Print #1, "exit"
Close #1
DoEvents
    
Shell AppDir & "ipconfig_t.bat", vbMinimizedFocus

Dim Counter As Integer
For Counter = 0 To 20000
    DoEvents
Next Counter

DoEvents
Me.SetFocus
'KMWarn.Visible = False
ProcessOutput
Kill AppDir & "ipconfig_t.bat"

'MsgBox "DNS Configuration has completed successfully", vbInformation, "X-Bot Automatic DNS Configuration"
End
End Sub
Sub ProcessOutput()

' Process output
On Error Resume Next

Dim Incoming As String
Incoming = ""
Open AppDir & "ipconfig_out.txt" For Input As #1
    Do Until InStr(LCase(Incoming), "dns servers")
        Line Input #1, Incoming
'        MsgBox Incoming
        DoEvents
    Loop
Close #1

Kill AppDir & "ipconfig_out.txt" 'ensure always getting new settings


' Incoming now has primary DNS server

Dim DNSServer As String
Dim Counter As Integer
Counter = 5 'x.x.x = 5 characters, smallest IP address

Do Until InStr(DNSServer, ":")
    DNSServer = Right(Incoming, Counter)
    DoEvents
    Counter = Counter + 1
Loop

DNSServer = Parse(DNSServer, ":", "")
DNSServer = Trim(DNSServer)

' Now write, replacing %dns with the dns server

Open AppDir & "windrop\resolv.xbot.conf" For Input As #1
Open AppDir & "windrop\resolv.conf" For Output As #2
    Do Until EOF(1)
        Line Input #1, Incoming
        Print #2, Parse(Incoming, "%dns", DNSServer)
    Loop
Close



End Sub

